<template>
    <!-- 展示全部订单的结构 -->
    <el-card class="box-card">
        <template #header>
            <div class="card-header">
                <span>挂号订单</span>
            </div>
        </template>
        <!-- 用户选择的下拉菜单 -->
        <el-form :inline="true">
            <el-form-item label="就诊人">
                <el-select @change="changeUser" placeholder="请选择就诊人" v-model="patientId">
                    <el-option label="请选择全部就诊人" value=""></el-option>
                    <el-option v-for="item in allUser" :value="item.id" :key="item.id" :label="item.name"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="订单状态">
                <el-select @change="changeOrderState" placeholder="请选择订单状态" v-model="orderStatus">
                    <el-option label="全部订单" value=""></el-option>
                    <el-option v-for="(item, index) in allOrderState" :key="index" :label="item.comment"
                        :value="item.status"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <!-- 表格展示订单的数据 -->
        <el-table border style="margin:10px 0px;" :data="allOrderArr">
            <el-table-column label="就诊时间" prop="reserveDate"></el-table-column>
            <el-table-column label="医院" prop="hosname"></el-table-column>
            <el-table-column label="科室" prop="depname"></el-table-column>
            <el-table-column label="医生" prop="title"></el-table-column>
            <el-table-column label="服务费" prop="amount"></el-table-column>
            <el-table-column label="就诊人" prop="patientName"></el-table-column>
            <el-table-column label="订单状态" prop="param.orderStatusString"></el-table-column>
            <el-table-column label="操作">
                <template #="{ row }">
                    <el-button type="text" @click="goDetail(row)">详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination @size-change="handler" @current-change="getOrderInfo" v-model:current-page="pageNo"
            v-model:page-size="pageSize" :page-sizes="[10, 20, 30, 40]" :background="true"
            layout="prev, pager, next, jumper,->,sizes,total " :total="total" />
    </el-card>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { reqUserOrderInfo, reqAllUser, reqOrderState } from '@/api/user'
import { useRouter } from 'vue-router';
let $router = useRouter()
let pageNo = ref(1)
let pageSize = ref(10)
// 就诊人的id
let patientId = ref('')
// 订单的状态
let orderStatus = ref('')
// 存储全部的订单
let allOrderArr = ref([])
// 存储订单的总数
let total = ref(0)
// 存储全部就诊人信息
let allUser = ref<any>([])
// 存储全部订单的状态
let allOrderState = ref<any>([])
onMounted(() => {
    getOrderInfo()
    getData()
})
// 获取订单的方法
const getOrderInfo = async (pager: any = 1) => {
    pageNo.value = pager
    let result = await reqUserOrderInfo(pageNo.value, pageSize.value, patientId.value, orderStatus.value)
    if (result.code == 200) {
        allOrderArr.value = result.data.records
        total.value = result.data.total
    }
}
// 点击订单详情按钮的回调
const goDetail = (row: any) => {
    $router.push({ path: '/user/order', query: { orderId: row.id } })
}
// 分页器下拉菜单的回调
const handler = (pageSizes: any) => {
    pageSize.value = pageSizes
    getOrderInfo()
}
// 获取就诊人与订单状态的方法
const getData = async () => {
    const result = await reqAllUser()
    const result1 = await reqOrderState()
    allUser.value = result.data
    allOrderState.value = result1.data
}
// 就诊人下拉菜单回调方法
const changeUser = () => {
    getOrderInfo()
}

// 订单状态下拉菜单回调方法
const changeOrderState = () => {
    getOrderInfo()
}
</script>

<style scoped></style>